class Solution
{
public:
    bool checkPossibility(vector<int> &nums)
    {
        bool changed = false;
        int n = nums.size();
        for (int i = 1; i < n; ++i)
        {
            if (nums[i] < nums[i - 1])
            {
                if (changed)
                {
                    return false;
                }
                if (i == 1 || nums[i] >= nums[i - 2])
                {
                    changed = true;
                }
                else
                {
                    nums[i] = nums[i - 1];
                    changed = true;
                }
            }
        }
        return true;
    }
};